package com.googlecode.gwt.test.plugin.editors;


import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.QualifiedName;

import com.googlecode.gwt.test.plugin.resourcesListner.CustomKeyWordsResource;

public class ProjectPluginProperty {
	private static ProjectPluginProperty instance = null;

	public KeyWords getKeyWords(IProject project) {
		try {
			KeyWords retour = (KeyWords) project.getSessionProperty(new QualifiedName("com.googlecode.gwt.test.plugin.preferences.propertyPage.project",
					"keyWords"));
			if (retour == null) {
				retour = new KeyWords(project);
				project.setSessionProperty(new QualifiedName("com.googlecode.gwt.test.plugin.preferences.propertyPage.project", "keyWords"), retour);
			}
			return retour;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public MacroResource getMacroResource(IProject project) {
		try {
			MacroResource retour = (MacroResource) project.getSessionProperty(new QualifiedName(
					"com.googlecode.gwt.test.plugin.preferences.propertyPage.project", "macroRessources"));
			if (retour == null) {
				retour = new MacroResource();
				project.setSessionProperty(new QualifiedName("com.googlecode.gwt.test.plugin.preferences.propertyPage.project", "macroRessources"), retour);
			}
			return retour;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static ProjectPluginProperty getInstance() {
		if (instance == null) {
			instance = new ProjectPluginProperty();
		}
		return instance;
	}

	private ProjectPluginProperty() {
	}

	public CustomKeyWordsResource getCustomKeyWordsResource(IProject project) {
		try {
			CustomKeyWordsResource retour = (CustomKeyWordsResource) project.getSessionProperty(new QualifiedName(
					"com.googlecode.gwt.test.plugin.preferences.propertyPage.project", "customKeywordRessources"));
			if (retour == null) {
				retour = new CustomKeyWordsResource();
				project.setSessionProperty(new QualifiedName("com.googlecode.gwt.test.plugin.preferences.propertyPage.project", "customKeywordRessources"),
						retour);
			}
			return retour;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
